package com.holyn.guofang.viewcommon.popupwindow;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;

import com.holyn.guofang.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * Created by Holyn on 2017/6/21.
 */

public class PopupAssistOperate extends BasePopupWindow implements View.OnClickListener{

    public static final int TYPE_ALBUM = 0;
    public static final int TYPE_TAKE_PHOTO = 1;
    public static final int TYPE_CROP = 2;
    public static final int TYPE_SPLIT_GROUP = 3;//分拆组合
    public static final int TYPE_REPLACE_ADD = 4;//替换追加
    public static final int TYPE_SPLIT_IMAGES = 5;//分卡图样

    public OnSelectListener onSelectListener;

    public void setOnSelectListener(OnSelectListener onSelectListener) {
        this.onSelectListener = onSelectListener;
    }

    public interface OnSelectListener{
        public void onSelect(int type);
    }

    public PopupAssistOperate(Activity context) {
        super(context, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        findViewById(R.id.tv_album).setOnClickListener(this);
        findViewById(R.id.tv_take_photo).setOnClickListener(this);
        findViewById(R.id.tv_crop).setOnClickListener(this);
        findViewById(R.id.tv_split_group).setOnClickListener(this);
        findViewById(R.id.tv_replace_add).setOnClickListener(this);
        findViewById(R.id.tv_split_images).setOnClickListener(this);
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.popup_assist_operate);
    }

    @Override
    public View initAnimaView() {
        return getPopupWindowView().findViewById(R.id.popup_container);
    }

    @Override
    protected Animation initShowAnimation() {
        AnimationSet set = new AnimationSet(true);
        set.setInterpolator(new DecelerateInterpolator());
//        set.addAnimation(getScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0));
        set.addAnimation(getTranslateAnimation(-200, 0, 300));
        set.addAnimation(getDefaultAlphaAnimation());
        return set;
//        return null;
    }

    @Override
    public View getClickToDismissView() {
        return null;
    }

    @Override
    public void showPopupWindow(View v) {
//        setOffsetX(-(getPopupViewWidth() - v.getWidth()));
        setOffsetX(0);
        setOffsetY(v.getHeight()+1);
        super.showPopupWindow(v);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_album:
                onSelectListener.onSelect(TYPE_ALBUM);
                break;
            case R.id.tv_take_photo:
                onSelectListener.onSelect(TYPE_TAKE_PHOTO);
                break;
            case R.id.tv_crop:
                onSelectListener.onSelect(TYPE_CROP);
                break;
            case R.id.tv_split_group:
                onSelectListener.onSelect(TYPE_SPLIT_GROUP);
                break;
            case R.id.tv_replace_add:
                onSelectListener.onSelect(TYPE_REPLACE_ADD);
                break;
            case R.id.tv_split_images:
                onSelectListener.onSelect(TYPE_SPLIT_IMAGES);
                break;
        }
        PopupAssistOperate.this.dismiss();
    }
}
